import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list = new ArrayList<>(); //二维
        List<Integer> row = new ArrayList<>(); //对行处理
        row.add(1);
        list.add(row);
        //至此，第一行处理完毕

        //对第二行以后 进行处理
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>(); //对行处理
            curRow.add(1); //新的一行第一个值

            List<Integer> previousRow = list.get(i - 1); //获取上一行
            for (int j = 1; j < i; j++) {
                int x = previousRow.get(j) + previousRow.get(j - 1);
                curRow.add(x);
            }

            curRow.add(1); //新的一行最后一个值

            list.add(curRow);
        }
        return list;
    }

    public static void main8(String[] args) {
        //杨辉三角
        System.out.println(generate(5));
    }




    public static ArrayList<Character> del(String s1, String s2) {
        ArrayList<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);
            if (!s2.contains(ch + "")) {
                arrayList.add(ch);
            }
        }
        return arrayList;
    }
    public static void main(String[] args) {
        //练习（笔试题）：删除第一个字符串中出现的 所有的 第二个字符串中的字符
        String s1 = "welcome to cctv";
        String s2 = "come";
        ArrayList<Character> ret = del(s1, s2);
        for (Character x : ret) {
            System.out.print(x);
        }
    }




    public static void main4(String[] args) {
        //遍历
        ArrayList<Integer> arrayList = new ArrayList<>(); //无参
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        //方式一：sout
        System.out.println(arrayList); //源码中重写了toString方法
        System.out.println("==========================");
        //方式二：for循环
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();

        for (Integer x : arrayList) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("==========================");
        //方式三：迭代器
        Iterator<Integer> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

        ListIterator<Integer> listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next() + " ");
        }
        System.out.println();

        //逆序输出
        ListIterator<Integer> listIterator1 = arrayList.listIterator(arrayList.size());
        while (listIterator1.hasPrevious()) {
            System.out.print(listIterator1.previous() + " ");
        }
        System.out.println();

    }



    public static void main3(String[] args) {
        //调用无参构造方法时，不分配内存
        ArrayList<Integer> arrayList = new ArrayList<>(); //无参

        //默认在第一次调用add方法时，才分配大小为10的内存空间
        //空间不够需扩容时，以1.5倍大小扩容
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        System.out.println(arrayList);

        //使用subList可以对顺序表进行截取
        List<Integer> ret = arrayList.subList(1, 3); //左闭右开区间
        System.out.println(ret);
        System.out.println("================");
        //当修改截取内容的值时，原顺序表中对应位置的值也会被修改
        ret.set(1, 666);
        System.out.println(ret);
        System.out.println(arrayList);

        //使用remove删除时，要想删除值，需要通过new关键字
//        arrayList.remove(2);
//        System.out.println(arrayList);
//        arrayList.remove(new Integer(5));
//        System.out.println(arrayList);

    }



    public static void main2(String[] args) {
        //三种构造
        ArrayList<Integer> arrayList = new ArrayList<>(); //无参
        List<Integer> list = new ArrayList<>(6); //指定容量
        list.add(1);
        list.add(1);
        list.add(1);

        List<Integer> list1 = new ArrayList<>(list); //参数为 顺序表
        list1.add(666);
        System.out.println(list1);

    }



    public static void main1(String[] args) {
        //myArrayList测试
        MyArrayList myArrayList = new MyArrayList(2);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
//        myArrayList.add(1, 99);
//        //myArrayList.add(-1, 99);
//        System.out.println(myArrayList.contains(1));
//        System.out.println(myArrayList.contains(666));
//        System.out.println(myArrayList.indexOf(99));
//        System.out.println(myArrayList.indexOf(666));
//        System.out.println(myArrayList.get(3));
//        //System.out.println(myArrayList.get(666));
        myArrayList.set(1, 99);
        //myArrayList.set(666, 99);
        //myArrayList.remove(99);
        myArrayList.remove(666);
        myArrayList.display();
        //myArrayList.clear();
        //myArrayList.display();
    }
}
